package com.doubledr.light_lock.utils;

import android.content.Context;
import android.os.Environment;

import com.doubledr.light_lock.R;

import java.io.File;

//获取存储路径的工具类
public class PathManager {

    public static String getEncrytDir(Context context){
        return getFilePath(context,"files_lock/"+context.getString(R.string.en_folder));
    }
    public static String getDecrytDir(Context context){
        return getFilePath(context,"files_lock/"+context.getString(R.string.de_folder));
    }
    public static String getRootDir(Context context){
        return getFilePath(context,"files_lock");
    }

    public static String getFilePath(Context context, String dir) {

        String directoryPath="";
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ) {//判断外部存储是否可用
            directoryPath =context.getExternalFilesDir(dir).getAbsolutePath();
        }else{//没外部存储就使用内部存储
            directoryPath=context.getFilesDir()+ File.separator+dir;
        }
        File file = new File(directoryPath);
        if(!file.exists()){//判断文件目录是否存在
            file.mkdirs();
        }
        return directoryPath;
    }
}
